package com.yksj.healthtalk.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

public class DoctorPatientListEntity implements Serializable,Comparator{

	private String doctorList;
	private String num;
	private String list;
	private String name;
	private String index;
	private String id;
	private List<UrlEntity> urlEntities;
	
	public List<UrlEntity> getUrlEntities() {
		return urlEntities;
	}
	public void setUrlEntities(List<UrlEntity> urlEntities) {
		this.urlEntities = urlEntities;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getDoctorList() {
		return doctorList;
	}
	public void setDoctorList(String doctorList) {
		this.doctorList = doctorList;
	}
	public String getNum() {
		return num;
	}
	public void setNum(String num) {
		this.num = num;
	}
	public String getList() {
		return list;
	}
	public void setList(String list) {
		this.list = list;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public String getIndex() {
		return index;
	}
	
	public void setIndex(String index) {
		this.index = index;
	}
	
	public static List<DoctorPatientListEntity> parseToList(String str){
		List<DoctorPatientListEntity> list=new ArrayList<DoctorPatientListEntity>();
		try {
			JSONArray array=new JSONArray(str);
			int length=array.length();
			for (int i = 0; i < length; i++) {
				JSONObject object = (JSONObject) array.get(i);
				DoctorPatientListEntity mEntity=new DoctorPatientListEntity();
				JSONObject ject = (JSONObject) object.get("doctorList");
				mEntity.setNum(ject.getString("num"));
				mEntity.setList(ject.getJSONArray("list").toString());
				mEntity.setName(object.getString("name"));
				mEntity.setIndex(object.getString("index"));
				mEntity.setId(object.getString("id"));
				
				final JSONArray array2 = ject.getJSONArray("list");
				final int size = array2.length();
				final List<UrlEntity> entitys = new ArrayList<UrlEntity>(size);
				for (int j = 0; j < size; j++) {//CUSTOMER_SEX
					UrlEntity entity=new UrlEntity();
					entity.setSex(array2.getJSONObject(j).getString("CUSTOMER_SEX"));
					entity.setUrl(array2.getJSONObject(j).getString("CLIENT_ICON_BACKGROUND"));
					entitys.add(entity);
				}
				mEntity.setUrlEntities(entitys);
				list.add(mEntity);
			}
		} catch (Exception e) {
			return null;
		}
		Collections.sort(list,new DoctorPatientListEntity());
		return list;
	}
	
	@Override
	public int compare(Object object1, Object object2) {
		DoctorPatientListEntity obj1=(DoctorPatientListEntity)object1;
		DoctorPatientListEntity obj2=(DoctorPatientListEntity)object2;
		return (Integer.valueOf(obj1.getIndex()))-(Integer.valueOf(obj2.getIndex()));
	}
	
	
}
